<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/logic/factory/CommandFactory.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/FirePHPCore-0.3.2/lib/FirePHPCore/FirePHP.class.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	class PresenterCreateDepartment {
		
		public function __construct() {}
		
		public function clickCreateDepartment ($department) {
			$GLOBALS['debug'] -> log($department['dpto'], " nombre sucursal PRESENTER");
			$GLOBALS['debug'] -> log($department['branch'], " Nombre sucursal PRESENTER");
			$command = CommandFactory :: createCommandCreateDepartment($department['name'],$department['dpto']) ;
			
			$command -> execute();		
			return $command->getResult();
		
		}	
		
		/**
		 * Method to execute to select Departments
		 */
		public function selectDepartments() {
			$command = CommandFactory :: createCommandSelectDepartments();
				$GLOBALS['debug']->log('INICIO Funcion PRESENTADOR LISTA DE DEPARTAMENTOS');
			$command -> execute();
			$departments = $command -> getResult();
			
			$result = '<table class="formTable" cellspacing="0" cellpadding="5">';
			$result .= '<tr class="odd">';
			$result .= '<td align="center"><b>RIF</b></td>';
			$result .= '<td align="center"><b>Nombre</b></td>';
			$result .= '<td align="center"><b>Sucursal</b></td>';
		

			$result .= '</tr>';
			$i = 0; $unread = 0;
			while ($i < count($departments['pk_rif'])) {
				if ($i % 2 == 0) $result .= '<tr class="even">';
				else $result .= '<tr class="odd">';
				
				$result .= '<td align="center">' . $departments['pk_rif'][$i] . '</td>';	
				$result .= '<td align="center">' . $departments['name_department'][$i] . '</td>';
				$result .= '<td align="center">' . $departments['name_branch'][$i++] . '</td>';
			

			

				$result .= '</tr>';
			}
			
		
				$GLOBALS['debug']->log('FIN Funcion PRESENTADOR LISTA DE DEPARTAMENTOS');
			return $result;
		}
		/**
		 * Method to execute to load all existing branch
		 */
		public function loadExistingBranch() {
			$command = CommandFactory :: createCommandSelectBranch();
			$command -> execute();
			$dpto = $command -> getResult();
			
			$result = '<select name="dpto" onchange="">';
			$result .= '<option value="0">Seleccione una Sucursal</option>';
			$i = 0;
			
			while ($i < count($dpto['pk_rif'])) {
				$result .= '<option value="' . $dpto['pk_rif'][$i] . '">' . 
					$dpto['name'][$i];
			
				$result .= '</option>';
				
				$i++;
			}
			
			$result .= '</select>';
			
			return $result;
		}
		
		
	}
?>